<template>
  <div>
    当前的加法值是：{{ $store.state.count }}
    <button @click="handel">+1按钮</button>
    <button @click="handelN">+N按钮</button>
    <button @click="handelAsync">+1按钮 1s后加1异步async</button>
    <button @click="handelNAsync">+N按钮 1s后加N异步async</button>
  </div>
</template>
<script>
export default {
  data() {
    return {};
  },
  methods: {
    handel() {
      this.$store.commit("add");
    },
    handelN() {
      this.$store.commit("addN", 4);
    },
    // 异步
    handelAsync() {
      // 这里的dispatch函数，专门用来触发action
      this.$store.dispatch("addAsync");
    },
    handelNAsync() {
      this.$store.dispatch("addNAsync", 10);
    },
  },
};
</script>